Fix using setFilters() does not trigger "afterUpdateRuleFilter"#353
Conversation
Because of the way DOM elements are updated in place with setFilters, we need to manually trigger the event or it will be omitted.
|
The rule filter did not changed, so it makes no sense to trigger "afterUpdateRuleFilter". If you have special logic to apply to the DOM, then listen to "afterSetFilters" too. |
|
Hey, when I opened the PR yesterday it was at the end of a very tiring workday. I probably wasn't as descriptive as I could've been, so let me elaborate. We need to trigger In my use case, I listen to ``afterCreateRuleFilters Afterwards, you manually call That's why we need to trigger the Then, in my plugin I can do: this.on('afterUpdateRuleFilter', function(e, rule) {
rule.$el.find(QueryBuilder.selectors.rule_filter).trigger('chosen:updated');
});An alternative approach could be to change the template for to: I should note that this problem arises both when manually using |
|
Yeah I understood the first time, but my point is that events triggered by the plugin represent changes in the data model, and in this case the data model did not changed, only the DOM. What you want is exactly what the plugin his doing itself for 'bt-selectpicker' plugin Hence my suggestion to also listen to 'afterSetFilters' and refresh all Chosen at once. |
|
I do believe that either of my proposed changes are a cleaner path to achieve this behavior. If the data did not change, then we probably want to render the DOM in the right state immediately by updating the template to set the |
|
Right. Actually my assertion is false because events like "afterCreateRuleFilters" do not reflect a change in the model. I'll see tomorrow. |
|
Thank you. |
|
About |
Because of the way DOM elements are updated in place with setFilters,
we need to manually trigger the event or it will be omitted.
Sorry, but I don't know how to write a test for this.